/**
 * 
 */
package com.example.radioclub.music.tasks;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import com.example.radioclub.data.Constants;
import com.example.radioclub.music.interfaces.IRestMusic;
import com.example.radioclub.types.ChartSong;

import android.os.AsyncTask;

/**
 * This async task uses the URL to get the JSON string containing the music
 * informations. Then this instance will transform the JSON string to array of
 * music.
 * 
 * 
 * @author wizard
 * 
 */
public class RestMusicDownloader extends AsyncTask<String, Void, String> {
	private final String TAG = Constants.APP_TAG + "Rest Music Download";
	private RestTemplate mapiRestTemplate;
	private IRestMusic listener;

	public RestMusicDownloader(RestTemplate mapiRestTemplate, IRestMusic listener) {
		this.mapiRestTemplate = mapiRestTemplate;
		this.listener = listener;
	}

	@Override
	protected String doInBackground(String... params) {
		// TODO Auto-generated method stub
		ResponseEntity<String> result = this.mapiRestTemplate.getForEntity(params[0], String.class);
		return result.getBody();
	}

	@Override
	protected void onPostExecute(String result) {
		// TODO Auto-generated method stub
		this.listener.onMusicFinished(result);
		super.onPostExecute(result);
	}

}
